package com.fanilycar51.mvp.manager;

import android.support.v4.widget.SwipeRefreshLayout;

/**
 * 创建日期：2017/8/2  9:42
 * 描述:SwipeRefreshLayout的管理类,用于设置一些通用样式
 * 作者:张伟
 */

public class SplManager {
    /**
     * @param spl    下拉刷新控件
     * @param colors 下拉刷新的样式颜色数组
     */
    public static void setSplStyle(SwipeRefreshLayout spl, int... colors) {
        //设置下拉进度的背景颜色,默认就是白色
        spl.setProgressBackgroundColorSchemeResource(android.R.color.white);
        //设置下拉进度的主题颜色
        spl.setColorSchemeColors(colors);
    }


    /**
     * 设置SwipeRefreshLayout的方法
     *
     * @param spl
     * @param colors
     */
    public static void setSpl(SwipeRefreshLayout spl, final OnSplRefreshLinstener linstener, int... colors) {
        setSplStyle(spl, colors);
        spl.measure(0, 0);
        spl.setRefreshing(true);
        //设置下拉的监听
        spl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (linstener != null) {
                    linstener.onRefresh();
                }
            }
        });
    }

    public static void setSpl(SwipeRefreshLayout spl, boolean flag, final OnSplRefreshLinstener linstener, int... colors) {
        setSplStyle(spl, colors);
        //设置下拉的监听
        spl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (linstener != null) {
                    linstener.onRefresh();
                }
            }
        });
    }
}
